package cn.sofwin.sb;


import cn.sofwin.sb.core.annotation.MyDao;
import cn.sofwin.sb.dao.UserDao;
import cn.sofwin.sb.entity.User;
import cn.sofwin.sb.service.UserService;

import java.lang.reflect.Field;

public class Main {
    public static void main(String[] args) {

        UserService userService=null;
        initAutowired(userService);
        System.out.println( );


    }
/*cxq_edit2修改*/
    public static  void initAutowired(Object obj){
        Field[] fields = obj.getClass().getDeclaredFields();
        try {
            for(Field field:fields){
                MyDao anno= field.getAnnotation(MyDao.class);
           if(anno!=null){
               System.out.println("发现同志: "+field.getName());
              //第一阶段 设置属性值
              field.setAccessible(true);
             //  field.set(obj,new UserDao());
               //第二阶段 动态设置对应数据类型的对象
               System.out.println(field.getGenericType());
               field.set(obj,field.getType().newInstance());
           }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
